package lc.栈;

import java.util.Stack;

/**
 * @description: 用栈实现队列
 * @author: qian
 * @createDate: 2021/9/30
 */
public class Math232 {

    Stack<Integer> inStack;
    Stack<Integer> outStack;

    public Math232() {
        inStack = new Stack<>();
        outStack = new Stack<>();
    }

    public void push(int x) {

        inStack.push(x);
    }

    public int pop() {

        if (outStack.isEmpty()) {
            while (!(inStack.isEmpty())) {
                outStack.push(inStack.pop());
            }
        }
        return outStack.pop();
    }

    public int peek() {
        if (outStack.isEmpty()) {
            while (!(inStack.isEmpty())) {
                outStack.push(inStack.pop());
            }
        }
        return outStack.peek();

    }

    public boolean empty() {

        return inStack.isEmpty() && outStack.isEmpty();
    }
}
